package com.qf.flash.ui.home.adapter;

import android.app.Activity;
import android.app.LauncherActivity;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.qf.flash.R;
import com.qf.flash.http.response.BannerBean;
import com.qf.flash.http.response.PlayTypeBean;
import com.qf.flash.model.HomeTopBean;
import com.qf.flashlib.adapter.BaseRViewItem;
import com.qf.flashlib.adapter.RVAdapter;
import com.qf.flashlib.adapter.RViewHolder;
import com.zhouwei.mzbanner.MZBannerView;
import com.zhouwei.mzbanner.holder.MZHolderCreator;

import java.util.List;

import butterknife.BindView;

/**
 * 创建日期：2020/2/23 on 10:55
 * 描述:
 * 作者:戴旭东
 */
public class HomeTopItem extends BaseRViewItem<Object> {

    private static final int BANNER_DELAY_TIME = 15000;   //Banner滚动循环时间

    private Activity activity;


    public HomeTopItem(Activity activity) {
        this.activity = activity;
    }

    @Override
    public boolean isItemView(Object entity, int position) {
        return entity instanceof HomeTopBean;
    }

    @Override
    public int getItemLayout() {
        return R.layout.item_home_top;
    }

    @Override
    public void convert(RViewHolder holder, Object entity, int position, int itemSize) {
        HomeTopBean homeTopBean = (HomeTopBean) entity;
        MZBannerView mBanner = holder.getView(R.id.banner_homepage);
        RecyclerView rvType = holder.getView(R.id.rv_type);
        RVAdapter<PlayTypeBean> mTypeAdapter = new RVAdapter<>(new PlayTypeItem(activity));
        rvType.setAdapter(mTypeAdapter);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rvType.setLayoutManager(linearLayoutManager);
        mTypeAdapter.setDatas(homeTopBean.getPlayTypeBeans());

        List<BannerBean> banners = homeTopBean.getBannerBeans();
        if (banners == null || banners.size() == 0)
            return;
        mBanner.setIndicatorRes(R.drawable.shape_indicator_unselect, R.drawable.shape_indicator_selected);
        mBanner.getIndicatorContainer().setGravity(Gravity.CENTER_VERTICAL);
        mBanner.setDelayedTime(BANNER_DELAY_TIME);
        mBanner.setPages(banners, new MZHolderCreator<HomePageBannerViewHolder>() {
            @Override
            public HomePageBannerViewHolder createViewHolder() {
                return new HomePageBannerViewHolder();
            }
        });
        mBanner.start();
        holder.setOnClickListener(R.id.tv_more);
    }
}
